package com.szss.springbootfirst.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wcx
 * @date 2023/2/7 15:40
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class R {
    private Integer code;
    private String msg;
    private boolean result;
    private Map<String,Object> data = new HashMap<>();

    public static R ok(Map<String,Object> map){
        return new R(200,"成功",true,map);
    }

    public static R ok(){
        R r = new R();
        r.setCode(200);
        r.setMsg("成功");
        r.setResult(true);
        return r;
    }

    public R data(Map<String,Object> map){
        this.data = map;
        return this;
    }

    public R data(String key,Object obj){
        this.data.put(key,obj);
        return this;
    }

    public static R error(){
        return new R(500,"失败",false,null);
    }

}
